﻿using Acme.BookStore.Dishes;
using Acme.BookStore.RoomTypes;
using AutoMapper.Internal.Mappers;
using Microsoft.AspNetCore.Mvc;
using SC.UserCenter.Infra;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace Acme.BookStore.ProductSettingss
{
    /// <summary>
    ///商品设置接口实现
    /// </summary>
    [ApiExplorerSettings(GroupName = "v2")]
    public class ProductSettingsServices : ApplicationService, IProductSettingsServices
    {
        /// <summary>
        ///注入
        /// </summary>
        private readonly IRepository<ProductSettings> repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repository"></param>
        public ProductSettingsServices(IRepository<ProductSettings> repository)
        {
            this.repository = repository;
        }

        /// <summary>
        ///添加商品设置
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost("PostProductSettings")]
        public async Task<ApiResult> PostProductSettings(ProductSettingsDTO dto)
        {
            try
            {
                var list = ObjectMapper.Map<ProductSettingsDTO, ProductSettings>(dto);
                await repository.InsertAsync(list);
                return ApiResult.Ok(data: list);
            }
            catch (Exception ex)
            {

                ex.HelpLink = "操作失败";
                return ApiResult.Fail(msg: ex.Message);
            }
        }
    }
}
